/*
 * table_PostIncDecStack_t.c
 *
 *  Created on: 2012/06/29
 *      Author: guanxiaoying
 */

#include "../../parser/coredef.h"
typedef struct _POSTINCDECSTACK
{
	U4 kind;
	AST expr;
	AST operand;
} POSTINCDECSTACK, *PPOSTINCDECSTACK;
#define TableSize  (sizeof(POSTINCDECSTACK))
#define TableType  PPOSTINCDECSTACK
#define stTable stPostIncDecStackManager.memoryBlocks
#define maxTable stPostIncDecStackManager.maxRecordNum
#define  maxNumPerBlk  (stPostIncDecStackManager.astMaxNum_Block)

/* private field */
static TABLEMANAGER stPostIncDecStackManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};

static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stPostIncDecStackManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stPostIncDecStackManager,  resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stPostIncDecStackManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stPostIncDecStackManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stPostIncDecStackManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID )
{
	return maxTable;
}

static AST getExpr( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->expr;
}
static AST setExpr( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->expr = value;
}
static AST getOperand( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->operand;
}
static AST setOperand( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->operand = value;
}
static U4 getKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->kind;
}
static U4 setKind( AST index, U4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->kind = value;
}

const POSTINCDECSTACKACCESS stPostIncDecStkAccess = {
		ClearTable,
		ResetTable,
		AllocTable,
		getMaxLineNum,
		{
				getKind,
				setKind
		},
		{
				getOperand,
				setOperand
		},
		{
				getExpr,
				setExpr
		}
};
